import {message} from "@/utils/ElmessasgeUtils";

/**
 * 根据文件路径（包含文件名）获取文件类型
 * @param filePath
 */
export function getFileType(filePath: string): string {
    let result: string = 'unKnown';
    let fileType = filePath.substring(filePath.lastIndexOf(".") + 1).toLowerCase();
    switch (fileType) {
        case 'docx':
        case 'doc':
            result = 'docx';
            break;
        case 'xlsx':
        case 'xls':
            result = 'xlsx';
            break;
        case 'pptx':
        case 'ppt':
            result = 'pptx';
            break;
        case 'pdf':
            result = 'pdf'
            break;
        case 'txt':
            result = 'txt';
            break;
        case 'yml':
        case 'css':
        case 'py':
        case 'yaml':
        case 'bat':
        case 'log':
        case 'java':
        case 'cs':
        case 'sh':
        case 'vue':
        case 'ts':
        case 'xml':
        case 'js':
        case 'cfg':
        case 'json':
        case 'rtf':
        case 'md':
        case 'csv':
            result = 'text'
            break;
        case 'html':
            result = 'html'
            break;
        case 'jpg':
        case 'JPG':
        case 'png':
        case 'PNG':
        case 'JPEG':
        case 'ico':
        case 'GIF':
        case 'gif':
        case 'svg':
        case 'SVG':
            result = 'image'
            break;
        case 'mp3':
        case 'wav':
            result = 'audio';
            break;
        case 'mp4':
        case 'avi':
            result = 'video';
            break;
        case 'sql':
            result = 'sql';
            break;
        case 'exe':
            result = 'exe';
            break;
        case 'zip':
        case 'tar':
        case 'rar':
            result = 'zip';
            break;
    }

    return result;
}